home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / Tool Chest / Games / Game Sample Code / SpriteWorld 1.0b3 / Examples / SpaceRocks / ShipSprite.h < prev    next >
Encoding:
Text File  |  1993-06-13  |  4.6 KB  |  183 lines  |  [TEXT/KAHL]

  1. ///--------------------------------------------------------------------------------------
  2. //    ShipSprite.h
  3. //
  4. //    Created: 6/18/92 at 2:29:31 PM
  5. //    By:        Tony Myles
  6. //
  7. //    Copyright © 1992 Tony Myles, All rights reserved worldwide.
  8. ///--------------------------------------------------------------------------------------
  9.  
  10.  
  11. #ifndef __SHIPSPRITE__
  12. #define __SHIPSPRITE__
  13.  
  14. #ifndef __SPRITEWORLD__
  15. #include <SpriteWorld.h>
  16. #endif
  17.  
  18. #ifndef __SPRITELAYER__
  19. #include <SpriteLayer.h>
  20. #endif
  21.  
  22. #ifndef __SOUND__
  23. #include <Sound.h>
  24. #endif
  25.  
  26.  
  27.     // spaceship constants
  28. enum
  29. {
  30.     kNumberOfShipSprites = 1,
  31.     kNumberOfShipFrames = 30,
  32.     kNumberOfExplosionFrames = 0,
  33.     kTotalFrames = kNumberOfShipFrames + kNumberOfExplosionFrames,
  34.     kFirstShipFrame = 0,
  35.     kLastShipFrame = kNumberOfShipFrames - 1,
  36.     kFirstExplosionFrame = kNumberOfShipFrames,
  37.     kLastExplosionFrame = kFirstExplosionFrame + (kNumberOfExplosionFrames - 1),
  38.     kShipFrameResID = 1000,
  39.     kExplosionFrameResID = 2000,
  40.     kExplosionSoundResID = 1000,
  41.     kThrustSoundResID = 1001,
  42.     kMaxShipVelocity = 18,
  43.     kShipMoveTime = 30,
  44.     kShipFrameTime = 30,
  45.     kExplosionTickDelay = 15
  46. };
  47.  
  48.     // space shot constants
  49. enum
  50. {
  51.     kShotFrameResID = 2000,
  52.     kShotSoundResID = 1002,
  53.     kNumberOfShotSprites = 10,
  54.     kNumberOfShotFrames = 1,
  55.     kShotIntervalTicks = 6,
  56.     kShotSpeedFactor = 10,
  57.     kShotMoveTime = 16,
  58.     kShotLifeExpectancy = 20,
  59.     kShotPosOffset = 14
  60. };
  61.  
  62.  
  63. typedef Fixed Coordinate;
  64.  
  65.     // velocity data structure
  66. typedef struct
  67. {
  68.     Coordinate h;
  69.     Coordinate v;
  70. } Velocity;
  71.  
  72.  
  73. typedef struct ShotSpriteRec ShotSpriteRec;
  74. typedef ShotSpriteRec *ShotSpritePtr, **ShotSpriteHdl;
  75. typedef struct ShipSpriteRec ShipSpriteRec;
  76. typedef ShipSpriteRec *ShipSpritePtr, **ShipSpriteHdl;
  77.  
  78. struct ShotSpriteRec
  79. {
  80.         // shot spriteworld stuff
  81.     SpriteRec shotSprite;
  82.  
  83.         // shot movement stuff
  84.     Velocity shotVelocity;
  85.     Coordinate shotHorizLoc;
  86.     Coordinate shotVertLoc;
  87.  
  88.         // other shot stuff
  89.     ShipSpritePtr shipSpriteP;
  90.     long shotLife;
  91. };
  92.  
  93.  
  94.     // space ship data structure
  95. struct ShipSpriteRec
  96. {
  97.         // ship spriteworld stuff
  98.     SpriteRec shipSprite;
  99.     SpriteWorldPtr shipSpriteWorldP;
  100.     SpriteLayerPtr shipSpriteLayerP;
  101.     SpriteLayerPtr shotSpriteLayerP;
  102.     Rect shipWrapRect;
  103.  
  104.         // ship movement stuff
  105.     Velocity shotVelocityTable[kNumberOfShipFrames];
  106.     Velocity angularVelocityTable[kNumberOfShipFrames];
  107.     Velocity shipVelocity;
  108.     Coordinate shipHorizLoc;
  109.     Coordinate shipVertLoc;
  110.  
  111.         // ship shot stuff
  112.     ShotSpritePtr shotSpriteArray[kNumberOfShotSprites];
  113.     ShotSpriteRec shotSpriteStorage[kNumberOfShotSprites];
  114.     short shotCounter;
  115.     long shotTickDelay;
  116.  
  117.         // ship sound stuff    
  118.     SndChannelPtr shipSndChannelP;
  119.     SndChannelPtr shotSndChannelP;
  120.     SndCommand shipSndCmd;
  121.     SndCommand shotSndCmd;
  122.     Handle thrustSndH;
  123.     Handle shotSndH;
  124.     Handle explosionSndH;
  125.  
  126.         // ship miscellaneous stuff
  127.     Boolean isAlive;
  128. };
  129.  
  130.  
  131.     // fixed point math stuff
  132. #define    ff(x)    ((Fixed)(((long)(x)) << 16))
  133. #define    FixToShort(x)    ((short)((x) >> 16))
  134. #define    FixToDbl(x)    ldexp((double)(x), -16)
  135. #define    DblToFix(x)    ((Fixed)ldexp((x), 16))
  136. #define    RndFixToInt(x) ((int)((x)+FIX_HALF >> 16))
  137. #define    FixRound(x)    FixToi(x)
  138. #define    Frac2Fix(x)    ((x)>>14)
  139. #define    Fix2Frac(x)    ((x)<<14)
  140. #define    FracToDbl(x) ldexp((double)(x), -30)
  141. #define    DblToFrac(x) ((long)ldexp((x), 30))
  142.  
  143.  // keyboard constants
  144. enum
  145. {
  146.     kUpArrowKey = 0x7E,
  147.     kLeftArrowKey = 0x7B,
  148.     kRightArrowKey = 0x7C,
  149.     kSpaceBarKey = 0x31,
  150.     kCommandKey = 0x37,
  151.     kOptionKey = 0x3A,
  152.     kShiftKey = 0x38,
  153.     kEscapeKey = 0x35
  154. };
  155.  
  156. #define KeyMapLoMem ((unsigned char *)0x174)
  157. #define KeyIsDown(key) ((KeyMapLoMem[key >> 3] >> (key & 7)) & 1)
  158.  
  159.  
  160.     // miscellaneous constants
  161. #define kRadiansInCircle 6.283185307178
  162.  
  163.  
  164.     // function prototypes
  165. OSErr CreateShipSprite(ShipSpritePtr* shipSpriteP);
  166. void InitShipSprite(ShipSpritePtr shipSpriteP, SpriteWorldPtr spriteWorldP, SpriteLayerPtr shipSpriteLayerP, SpriteLayerPtr shotSpriteLayerP);
  167. void DisposeShipSprite(ShipSpritePtr shipSpriteP);
  168. OSErr CreateShipSounds(ShipSpritePtr shipSpriteP);
  169. void DisposeShipSounds(ShipSpritePtr shipSpriteP);
  170. void SetupShipSprite(ShipSpritePtr shipSpriteP);
  171. OSErr CreateShotSpriteArray(ShipSpritePtr shipSpriteP);
  172. void InitShotSprite(ShipSpritePtr shipSpriteP, ShotSpritePtr shotSpriteP);
  173. void DisposeShotSprite(ShipSpritePtr shipSpriteP);
  174. void CreateVelocityTable(Velocity *velocityTable, short numAngles, double radius);
  175. void FireAShot(ShipSpritePtr shipSpriteP);
  176. void ShipMoveProc(ShipSpritePtr shipSpriteP, Point *spriteLoc);
  177. void ShipFrameProc(ShipSpritePtr shipSpriteP, FramePtr curFrameP, long* curFrameIndex);
  178. void ShipCollideProc(ShipSpritePtr shipSpriteP, SpritePtr dstSpriteP, Rect* sectRect);
  179. void ShotMoveProc(ShotSpritePtr shotSpriteP, Point *spriteLoc);
  180.  
  181. pascal void ShipSoundCallBack(SndChannelPtr sndChannelP, SndCommand *sndCmdP);
  182.  
  183. #endif /* __SHIPSPRITE__ */